package org.spring.blog.pojo;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

@Data
@Accessors(chain = true)
public class LRPageList<T> implements Serializable {

    private static final long serialVersionUID = -3152791884381033409L;

    // 当前页的内容列表
    private List<T> content;

    // 总的页码数
    private long totalPages;

    // 当前页码
    private long currentPage;

    // 查到的总的数量
    private long totalElements;

    // 页面大小
    private long pageSize;

    // 是否是第一页
    private boolean isFirst;

    // 是否是最后一页
    private boolean isLast;


    public LRPageList(List<T> _content, long _currentPage, long _totalElements, long _pageSize) {
        content = _content;
        currentPage = _currentPage;
        totalElements = _totalElements;
        pageSize = _pageSize;

        // 强转的确会损失精度，但是我们需要
        totalPages = (long) (totalElements / (pageSize * 1.0f) + 0.9f);


        isFirst = currentPage == 1;
        isLast = currentPage == totalPages;
    }

    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
        throw new java.io.NotSerializableException("org.spring.blog.pojo.PageList");
    }

    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
        throw new java.io.NotSerializableException("org.spring.blog.pojo.PageList");
    }
}
